package com.lbloca.locate.ui.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;


import com.gyf.immersionbar.ImmersionBar;
import com.lbloca.locate.R;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseImmersionBarFragment extends Fragment {
    private Unbinder unbinder;
    protected Context mContext;

    protected View statusBarView;
    protected Toolbar toolbar;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(getLayoutId(), container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        unbinder = ButterKnife.bind(this, view);
        toolbar = view.findViewById(R.id.id_toolbar);
        fitsLayoutOverlap();
        initView(view);
        initData();
        initEvent();
    }

    @Override
    public void onAttach(Context context) {
        mContext = context;
        super.onAttach(context);
    }

    protected abstract int getLayoutId();

    /**
     * 初始化
     */
    protected abstract void initView(View view);

    protected abstract void initData();


    protected abstract void initEvent();

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null)
            unbinder.unbind();
    }

    private void fitsLayoutOverlap() {
        if (statusBarView != null) {
            ImmersionBar.setStatusBarView(this, statusBarView);
        } else {
            ImmersionBar.setTitleBar(this, toolbar);
        }
    }



}
